Skip to content

Add ORT_ENFORCE for swiglu_fusion==1 in QMoECPU to prevent out-of-bounds read#27748

Merged
tianleiwu merged 1 commit intomainfrom
copilot/update-qmoe-cpu-operator
Mar 19, 2026
Merged

Add ORT_ENFORCE for swiglu_fusion==1 in QMoECPU to prevent out-of-bounds read#27748
tianleiwu merged 1 commit intomainfrom
copilot/update-qmoe-cpu-operator

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

Description

Add an ORT_ENFORCE check in the QMoECPU constructor to require swiglu_fusion == 1 when using SwiGLU activation, preventing an out-of-bounds read.

When swiglu_fusion=0 (the default), fc1_out_features is computed as inter_size instead of 2*inter_size. However, ApplySwiGLUActivation reads 2*inter_size values from the FC1 output buffer (via input_data[2*i] for i in [0, inter_size)), causing an out-of-bounds read that produces NaN on Windows x86.

This matches the existing validation already present in the MoE CPU operator (moe_cpu.cc:26-27).

Motivation and Context

  • The NaN was caused by a missing swiglu_fusion=1 attribute. With the default swiglu_fusion=0, the SwiGLU activation reads past the allocated FC1 output buffer — an out-of-bounds read.
  • The MoE CPU operator already enforces swiglu_fusion == 1 for SwiGLU; this change adds the same guard to QMoECPU for consistency and safety.
  • Non-interleaved SwiGLU format (swiglu_fusion=2) is not implemented (throws ORT_NOT_IMPLEMENTED), and swiglu_fusion=0 is invalid for SwiGLU, so only swiglu_fusion=1 is valid.

…t out-of-bounds read

Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
@tianleiwu tianleiwu requested a review from apsonawane March 18, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants